export function getAuthority() {
    const user = JSON.parse(localStorage.getItem('userInfo'))
    if (!user) {
        return null
    }
    const { buttons } = user
    let auths = []
    buttons.forEach(button => {
        auths.push(button.name)
    });
    return auths
}

export function check(authority) {
    const current = getAuthority()
    if (!current) {
        return false
    }
    return current.some(item => authority.includes(item))
}

// v-auth 指令设计
export default function install(Vue, options = {}) {    
    Vue.directive(options.name || 'auth', {
        inserted(el, binding) {
            // console.log('auth');
            if (!check(binding.value)) {
                el.parentNode && el.parentNode.removeChild(el)
            }
        }
    })
}
